int is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= int(sqrt(num)) + 1; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}


void find_prime(std::string s) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::vector<std::string> words;
    std::stringstream ss(s);
    std::string word;
    while (ss >> word) {
        words.push_back(word);
    }

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return;
    }

    std::string number = "";
    for (const std::string& w : words) {
        if (numbers.find(w) != numbers.end()) {
            number += std::to_string(numbers[w]);
        } else {
            std::cout << "Wrong input" << std::endl;
            return;
        }
    }

    int num = std::stoi(number);

    if (num >= 100 && num <= 999 && is_prime(num)) {
        std::cout << num << std::endl;
        return;
    }

    int lower = num - 1;
    int upper = num + 1;
    while (true) {
        if (lower >= 100 && is_prime(lower)) {
            std::cout << lower << std::endl;
            return;
        } else if (upper <= 999 && is_prime(upper)) {
            std::cout << upper << std::endl;
            return;
        }
        lower--;
        upper++;
    }

    std::cout << "Wrong input" << std::endl;
}


int main() {
    std::string input_str;
    std::getline(std::cin, input_str);
    find_prime(input_str);

    return 0;
}
